<div>
	<div class="easyui-panel2" style="width:900px; height:570px;">
        <div style="width:320px; height:560px; float:left; overflow-y:auto"><ul id="id_acc_tree"></ul></div>
        <div style="width:580px; height:500px; float:left; padding:10px 10px;" class="acc_debug" id="id_accSet_detail">
            <label style="width:80px; display:inline-block;" for="id_account__id">科目id</label><input disabled="disabled" type="text" id="id_account__id" class="text ui-widget-content ui-corner-all" style="background-color:rgb(240, 240, 240); background-image:none">
            <div class='acc_clear' style='height:5px;'></div>
            <label style="width:80px; display:inline-block;" for="id_account__level">科目级别</label><input disabled="disabled" type="text" id="id_account__level" class="text ui-widget-content ui-corner-all" style="background-color:rgb(240, 240, 240); background-image:none">
            <div class='acc_clear' style='height:5px;'></div>
            <label style="width:80px; display:inline-block;" for="id_account__serialNo">科目编码</label><input disabled="disabled" type="text" id="id_account__serialNo" class="text ui-widget-content ui-corner-all" style="background-color:rgb(240, 240, 240); background-image:none">
            <div class='acc_clear' style='height:5px;'></div>
            <label style="width:80px; display:inline-block;" for="id_account__name">科目名称</label><input type="text" id="id_account__name" class="text ui-widget-content ui-corner-all">
            <div class='acc_clear' style='height:5px;'></div>
            <label style="width:80px; display:inline-block;" for="id_account__abbr">助词码</label><input type="text" id="id_account__abbr" class="text ui-widget-content ui-corner-all">
            <div class='acc_clear' style='height:15px;'></div>
            <fieldset style="width:300px; padding:5px 10px">
                <legend>辅助核算</legend>
                <input type="checkbox" id="id_account__auxCurrentCus" class="text ui-widget-content ui-corner-all"><label for="id_account__auxCurrentCus">客户</label>
                <div class='acc_clear' style='height:5px;'></div>
                <input type="checkbox" id="id_account__auxCurrentSup" class="text ui-widget-content ui-corner-all"><label for="id_account__auxCurrentSup">供应商</label>
                <div class='acc_clear' style='height:5px;'></div>
                <input type="checkbox" id="id_account__auxSaleMan" class="text ui-widget-content ui-corner-all"><label for="id_account__auxSaleMan">业务员</label>
                <div class='acc_clear' style='height:5px;'></div>
                <input type="checkbox" id="id_account__auxPrj1" class="text ui-widget-content ui-corner-all"><label for="id_account__auxPrj1">项目1</label>
                <div class='acc_clear' style='height:5px;'></div>
                <input type="checkbox" id="id_account__auxPrj2" class="text ui-widget-content ui-corner-all"><label for="id_account__auxPrj2">项目2</label>
                <div class='acc_clear' style='height:5px;'></div>
                <input type="checkbox" id="id_account__auxPrj3" class="text ui-widget-content ui-corner-all"><label for="id_account__auxPrj3">项目3</label>
                <div class='acc_clear' style='height:5px;'></div>
                <input type="checkbox" id="id_account__auxAccWay" class="text ui-widget-content ui-corner-all"><label for="id_account__auxAccWay">结算方式</label>
            </fieldset>
            <div class='acc_clear' style='height:15px;'></div>
            <fieldset style="width:300px; padding:5px 10px">
                <legend>余额方向</legend>
                <label for="">借方</label><input type="radio" value="cr" name="id_account__balanceDirect" id="id_account__balanceDirect_cr">
                <label for="">贷方</label><input type="radio" value="de" name="id_account__balanceDirect" id="id_account__balanceDirect_de">
            </fieldset>
        </div>
        <div>
            <div class="BtnLeftArrangeFirst"><button id="id_btn_accSet_cancel" style="height:30px; width:70px;" class="ui-widget ui-button ui-corner-all">取消修改</button></div>
            <div class="BtnLeftArrange"><button id="id_btn_accSet_apply" style="height:30px; width:70px;" class="ui-widget ui-button ui-corner-all">应用</button></div>
        </div>
	</div>

    <ul id="id_tree_pop_menu" style="width:120px; display:none">
      <li><div id="id_popm_append"><span class="ui-icon ui-icon-plus"></span>Append</div></li>
      <li><div id="id_popm_remove"><span class="ui-icon ui-icon-minus"></span>Remove</div></li>
      <li>-</li>
      <li><div id="id_popm_expand"><span class="ui-icon ui-icon-arrow-4-diag"></span>Expand</div></li>
      <li><div id="id_popm_cllapse"><span class="ui-icon ui-icon-seek-end"></span>Collapse</div></li>
      <li>-</li>
      <li><div id="id_popm_quit"><span class="ui-icon ui-icon-close"></span>关闭此菜单</div></li>
    </ul>

	<script type="text/javascript">
        var jt_data = [];
		function append(){
			var t = $('#id_acc_tree');
			var node = t.tree('getSelected');
			t.tree('append', {
				parent: (node ? node.target : null),
				data: [{
					text: 'new item1'
				},{
					text: 'new item2'
				}]
			});
		}
		function removeit(){
			var node = $('#id_acc_tree').tree('getSelected');
			$('#id_acc_tree').tree('remove', node.target);
		}
		function collapse(){
			var node = $('#id_acc_tree').tree('getSelected');
			$('#id_acc_tree').tree('collapse',node.target);
		}
		function expand(){
			var node = $('#id_acc_tree').tree('getSelected');
			$('#id_acc_tree').tree('expand',node.target);
		}

        function on_tree_pop_menu_selected(e, ui) {
            //console.log("eeeee " + event + ", ui:"  + ui);
            var menuId = ui.item.find("div").attr("id");
            switch(menuId) {
            case "id_popm_append":
                append();
                break;
            case "id_popm_remove":
                removeit();
                break;
            case "id_popm_expand":
                expand();
                break;
            case "id_popm_cllapse":
                collapse();
                break;
            }
            $(this).hide(); //$(this) == $("#id_tree_pop_menu")
        }

        function onClickAccTreeNode(node) {
            // $("#id_acc_level").val(node.attributes.level);
            // $("#id_acc_serialNo").val(node.attributes.serialNo);
            // $("#id_acc_name").val(node.attributes.name);
            // var bd = node.attributes.balanceDirect;
            // $("[name='balanceDirect']").filter("[value='" + bd + "']").attr("checked", true)
            // $("#id_acc_auxCurrentCus").prop("checked", false)
            console.debug("node:", node);
            set_inputs_elemnt_from_obj("id_", node.attributes);
        }
        
    function accSetApply_callback(ps_data) {
        if ("OK" != ps_data["result"]) {
            alert("保存失败!\n");
        } else {
            //update jt_data
            //var setdata =  get_inputs_data("id_accSet_detail", "id_");
            
            
            alert("保存成功");
            
            //g_is_new_voch_empty = 1;
        }
    }
        function onBtnAccSetApply() {
            var setdata =  get_inputs_data("id_accSet_detail", "id_");
            console.log(setdata);
            call_rpc("accSet_save", setdata, accSetApply_callback);
        }

        $(document).ready(function() {
            var mmu = $('#id_tree_pop_menu').menu({
                select: on_tree_pop_menu_selected,
            }).hide();
            acc_load_data("accounts_for_tree", function(ps_data) {
                if ("OK" == ps_data["result"]) {
                    jt_data = JSON.parse(ps_data["data"]);
                    $("#id_acc_tree").tree({
                        data:jt_data,
                        lines:true,
                        animate: true,
                        onContextMenu: function(e, node) {
                            e.preventDefault();
                            $("#id_acc_tree").tree('select',node.target);
                            mmu.show().position({
                                my: "left top",
                                of: e
                            });
                        },
                        onClick: onClickAccTreeNode,
                    });
                } else {
                    alert(ps_data["err_msg_display"] || "Internal Error! load data failed: " + ld_descriptor);
                }
            });
            $("#id_btn_accSet_apply").click(onBtnAccSetApply);
        });
	</script>
</div>